package com.demo.aop.pcut.regexp;

import com.demo.aop.pcut.stat.SimpleAdvice;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;

/**
 * 描述：
 *
 * @author lida
 * @time 2019/10/26 10:39
 */
public class RegexpMethodPointcutDemo {

	public static void main(String[] args) {
		Star s = new Star();
		JdkRegexpMethodPointcut pc = new JdkRegexpMethodPointcut();
		pc.setPattern(".*sing.*");
		pc.setPattern(".*get.*");
		Advisor advisor = new DefaultPointcutAdvisor(pc, new SimpleAdvice());

		ProxyFactory pf = new ProxyFactory();
		pf.setTarget(s);
		pf.addAdvisor(advisor);
		Star proxy = (Star) pf.getProxy();
		proxy.sing();
		proxy.sing("哈哈");
		proxy.setName("zhang");
		System.out.println(proxy.getName());
		System.out.println(proxy.getAge());
	}
}
